﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DocumentManagement.ViewsModels;
//using DocumentManagement.Interfaces;
using DocumentManagement.Models;


namespace DocumentManagement.Views
{
    /// <summary>
    /// Interaction logic for ShowItemDocumentInUserControl.xaml
    /// </summary>
    public partial class ShowItemDocumentInUserControl //: UserControl, ITabbedMDI 
    {
        //string mode;
       // private ContextMenu _contextMenu = null;
        public ShowItemDocumentInViewsModel _showItemDocumentInViewsModel;
        public ShowItemDocumentInUserControl()
        {
            InitializeComponent();
            _showItemDocumentInViewsModel = this.Resources["showItemDocumentInViewsModel"] as ShowItemDocumentInViewsModel;
           
        }

        private void ReceiveCodeOrTitleTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            //DateTime date1 = Convert.ToDateTime(ToDatePicker.SelectedDate.Value);
            _showItemDocumentInViewsModel.Filter(ReceiveCodeOrTitleTextBox.Text, FromDatePicker.SelectedDate, ToDatePicker.SelectedDate);
          //  _showItemDocumentInViewsModel.Filter(ReceiveCodeOrTitleTextBox.Text);
      
        }

        private void ToDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            //DateTime date1 = Convert.ToDateTime(ToDatePicker.SelectedDate.Value);
            // //DateTime date2 = Convert.ToDateTime(ToDatePicker);

            // _showItemDocumentViewsModel.Filter(date1);
            _showItemDocumentInViewsModel.Filter(ReceiveCodeOrTitleTextBox.Text, FromDatePicker.SelectedDate, ToDatePicker.SelectedDate);

        }

        private void FromDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
           _showItemDocumentInViewsModel.Filter(ReceiveCodeOrTitleTextBox.Text, FromDatePicker.SelectedDate, ToDatePicker.SelectedDate);
        }

        //#region Append from Implement Interface

        //public event delClosed CloseInitiated;
        //public string UniqueTabName
        //{
        //    get
        //    {
        //        return "InTab";
        //    }
        //}

        //public string Title
        //{
        //    get
        //    {
        //        return "หนังสือเข้า";
        //    }
        //}



        //#endregion

        private void addINDocMenu_Click(object sender, RoutedEventArgs e)
        {
            AddDocumentIn addWin = new AddDocumentIn(new Receive { ReceiveDate = DateTime.Now, DocumentDate = DateTime.Now }, _showItemDocumentInViewsModel.EntityModels);
            addWin.ShowDialog();
            //addWin.Unloaded += (s, args) =>
            //    {
            //        _showItemDocumentInViewsModel.RefreshData();
            //    };

          
        }

        void addWin_Unloaded(object sender, RoutedEventArgs e)
        {
            throw new NotImplementedException();
        }

        private void editINDocMenu_Click(object sender, RoutedEventArgs e)
        {
            AddDocumentIn editWin = new AddDocumentIn(_showItemDocumentInViewsModel.MySelectedEditItemReceive, _showItemDocumentInViewsModel.EntityModels);
            editWin.ShowDialog();
            //var win = new Window1(_showItemDocumentInViewsModel.MySelectedEditItemReceive);
            //win.ShowDialog();
        }

        private void deleteINDocMenu_Click(object sender, RoutedEventArgs e)
        {
            _showItemDocumentInViewsModel.DeleteFromDatabase();
        }

        private void DG_Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            ShowItemFileIn showFile = new ShowItemFileIn(_showItemDocumentInViewsModel.MySelectedEditItemReceive);
            showFile.ShowDialog();
        }

        private void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            //var i = sender;
            //var ii = 9;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
           
        }

       
    }
}
